
package biblio.util;


import biblio.util.interfaces.RequestOperationHelper;
import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


/**
 * Defines operations on context from JSF framework.
 * @author mephisto
 * 2011-10-30
 */
public class RequestOperationHelperImpl implements RequestOperationHelper
{
    /**
     * Default constructor.
     */
    public RequestOperationHelperImpl() {}

    public Object getBean(String attributeName)
    {
        return getRequest().getAttribute(attributeName);
    }

    public HttpServletRequest getRequest()
    {
        if (externalContext == null)
        {
            getFacesContext();
            getExternalContext();
        }
        return (HttpServletRequest) externalContext.getRequest();
    }

    public HttpServletResponse getResponse()
    {
        if (externalContext == null)
        {
            getFacesContext();
            getExternalContext();
        }
        return (HttpServletResponse) externalContext.getResponse();
    }

    public ExternalContext getExternalContext()
    {
        externalContext = facesContext.getExternalContext();
        return externalContext;
    }

    public FacesContext getFacesContext()
    {
        facesContext = FacesContext.getCurrentInstance();
        return facesContext;
    }


    private FacesContext facesContext;
    private ExternalContext externalContext;
//    private HttpServletRequest request;
//    private HttpServletResponse response;
}
